#include "func.h"

napi_threadsafe_function
createTSFWithCallback(napi_env env, const char *workName, void *callback) {
    napi_value workNameNapiValue = 0;
    napi_create_string_utf8(env, workName, NAPI_AUTO_LENGTH, &workNameNapiValue);
    napi_threadsafe_function tsfn;
    napi_create_threadsafe_function(env, 0, NULL, workNameNapiValue, 0, 1, NULL, NULL, NULL,
                                    (napi_threadsafe_function_call_js) callback, &tsfn);
    return tsfn;
}

void callTSFWithData(napi_threadsafe_function tsfn, void *data) {
    napi_acquire_threadsafe_function(tsfn);
    napi_call_threadsafe_function_with_priority(tsfn, data, napi_priority_high, true);
}

